package com.tcm.pay.web.controller;//package com.tcm.portal.web.controller;

import com.base.core.exception.ServiceException;
import com.base.core.utils.R;
import com.tcm.pay.service.OrderPayService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 问诊单支付
 */
@RequestMapping("/pay")
@RestController
public class ConsultationPayController {

    @DubboReference(version = "0.0.1-alpha", group = "consultation", check = false, timeout = 3000)
    private OrderPayService orderPayService;


    /**
     * 支付宝扫码支付
     *
     * @param userId
     * @param orderId
     * @return
     */
    @GetMapping("/consultation/alipay")
    public R orderAliPay(@RequestParam("userId") Long userId, @RequestParam("orderId") Long orderId) {
        Map<String, Object> rs;
        try{
           rs = orderPayService.alipay(userId, orderId);
        }catch (ServiceException e){
            return R.fail(e.getResult().getCode(), e.getMessage());
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.success(rs);
    }

    /**
     * 微信支付
     *
     * @param userId
     * @param orderId
     * @return
     */
    @GetMapping("/consultation/wxpay")
    public R orderWxPay(@RequestParam Long userId, @RequestParam Long orderId, @RequestParam String code) {
        Map<String, Object> rs;
        try{
            rs = orderPayService.wxpay(userId, orderId, code);
        }catch (ServiceException e){
            return R.fail(e.getResult().getCode(), e.getMessage());
        }catch (Exception e){
            return R.fail(e.getMessage());
        }
        return R.success(rs);
    }


}
